Skip to content

perf(StringRedisTemplate): avoid redundant logger creation in execute(). #3173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.5.x
Choose a base branch
from

Conversation

huangcanda
Copy link

Problem Description

Each invocation of StringRedisTemplate.execute() creates a new DefaultStringRedisConnection instance, resulting in repeated initialization of non-static logger instances. This causes redundant LogFactory lookups that ​consume an additional 10–15% CPU overhead.

Solution

Modify the private final Log logger field in DefaultStringRedisConnection to private static final Log logger.

Impact

10–15% reduction in CPU overhead for all Redis client command executions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 22, 2025
Static logger eliminates expensive initialization per invocation.

Signed-off-by: huangcanda <[email protected]>
@huangcanda huangcanda force-pushed the fix/string-redis-template-connection-perf branch from dcd43b7 to 41d4bda Compare June 22, 2025 07:37
@mp911de mp911de added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 23, 2025
@christophstrobl
Copy link
Member

Thanks for the heads up. There are a couple of other places in the codebase as well that would benefit from this kind of change. Would you like have a look and extend the PR to those, or should we take care of the rest.

@christophstrobl christophstrobl added the status: waiting-for-feedback We need additional information before we can continue label Jul 10, 2025
@huangcanda
Copy link
Author

Sure, I’d be happy to extend the PR.

However, since my initial change was based on a specific performance issue I encountered, I haven’t done a full review of the codebase.

If you could point me to the places you think would benefit from similar optimizations, I’ll gladly take a look and update the PR accordingly.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants